package com.zero.qth.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zero.common.core.domain.page.PageDomain;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.zero.common.annotation.log.Log;
import com.zero.common.core.basecontroller.BaseController;
import com.zero.common.core.domain.result.AjaxResult;
import com.zero.common.core.enums.BusinessType;
import com.zero.qth.domain.Driver;
import com.zero.qth.service.IDriverService;
import com.zero.common.core.utils.poi.ExcelUtil;
import com.zero.common.core.domain.page.TableDataInfo;

/**
 * 司机列表Controller
 * 
 * @author cai-xu-kun
 * @date 2025-08-02
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "司机列表")
@RequestMapping("/qth/driver")
public class DriverController extends BaseController {

    private final IDriverService driverService;

    @ApiOperation("查询司机下线列表")
    @PreAuthorize("@ss.hasPermi('qth:driver:list')")
    @GetMapping("/listChildren")
    //param传就用@RequestParam接
    public TableDataInfo listChildren(@RequestParam("pid") Long pid,
                                      @RequestParam(value = "pageNum", defaultValue = "1") Long pageNum,
                                      @RequestParam(value = "pageSize", defaultValue = "10") Long pageSize) {
//        PageDomain pageDomain = this.startPage();
//        Page<Driver> p = new Page<>(pageDomain.getPageNum(), pageDomain.getPageSize());
        Page<Driver> p = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Driver> qw = new LambdaQueryWrapper<Driver>().eq(Driver::getPid, pid);
        Page<Driver> resultPage = driverService.page(p,qw);
        return this.getDataTable(resultPage);
    }


/*=============================================================*/
    /**
     * 查询司机列表分页
     */
    @ApiOperation("查询司机列表分页")
    @PreAuthorize("@ss.hasPermi('qth:driver:list')")
    @GetMapping("/list")
    public TableDataInfo list(Driver driver) {
        PageDomain pageDomain = this.startPage();
        Page<Driver> p = new Page<>(pageDomain.getPageNum(), pageDomain.getPageSize());
        Page<Driver> page = driverService.selectDriverListPage(driver, p);
        return this.getDataTable(page);
    }

    /**
     * 导出司机列表列表
     */
    @ApiOperation("导出司机列表列表")
    @PreAuthorize("@ss.hasPermi('qth:driver:export')")
    @Log(title = "司机列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Driver driver) {
        List<Driver> list = driverService.selectDriverList(driver);
        ExcelUtil<Driver> util = new ExcelUtil<Driver>(Driver.class);
        util.exportExcel(response, list, "司机列表数据");
    }

    /**
     * 获取司机列表详细信息
     */
    @ApiOperation("获取司机列表详细信息")
    @PreAuthorize("@ss.hasPermi('qth:driver:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(driverService.selectDriverById(id));
    }

    /**
     * 新增司机列表
     */
    @ApiOperation("新增司机列表")
    @PreAuthorize("@ss.hasPermi('qth:driver:add')")
    @Log(title = "司机列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Driver driver) {
        return toAjax(driverService.insertDriver(driver));
    }

    /**
     * 修改司机列表
     */
    @ApiOperation("修改司机列表")
    @PreAuthorize("@ss.hasPermi('qth:driver:edit')")
    @Log(title = "司机列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Driver driver) {
        return toAjax(driverService.updateDriver(driver));
    }

    /**
     * 删除司机列表
     */
    @ApiOperation("删除司机列表")
    @PreAuthorize("@ss.hasPermi('qth:driver:remove')")
    @Log(title = "司机列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(driverService.deleteDriverByIds(ids));
    }
}
